package com.IntelligentCommunity.community.controller;

import com.IntelligentCommunity.common.core.domain.R;
import com.IntelligentCommunity.common.core.utils.poi.ExcelUtil;
import com.IntelligentCommunity.common.core.web.controller.BaseController;
import com.IntelligentCommunity.common.core.web.domain.AjaxResult;
import com.IntelligentCommunity.common.core.web.page.TableDataInfo;
import com.IntelligentCommunity.common.log.annotation.Log;
import com.IntelligentCommunity.common.log.enums.BusinessType;
import com.IntelligentCommunity.community.domain.RealSecurityFacilities;
import com.IntelligentCommunity.community.domain.RealSecurityFacilitiesType;
import com.IntelligentCommunity.community.service.IRealSecurityFacilitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 实有安防设施Controller
 *
 * @author IntelligentCommunity
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/facilities")
public class RealSecurityFacilitiesController extends BaseController
    {
    @Autowired
    private IRealSecurityFacilitiesService realSecurityFacilitiesService;

    /**
     * 查询实有安防设施列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RealSecurityFacilities realSecurityFacilities){
        startPage();
        List<RealSecurityFacilities> list = realSecurityFacilitiesService.selectRealSecurityFacilitiesList(realSecurityFacilities);
        return getDataTable(list);
    }

    /**
     * 导出实有安防设施列表
     */
    @Log(title = "实有安防设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RealSecurityFacilities realSecurityFacilities)
    {
        List<RealSecurityFacilities> list = realSecurityFacilitiesService.selectRealSecurityFacilitiesList(realSecurityFacilities);
        ExcelUtil<RealSecurityFacilities> util = new ExcelUtil<RealSecurityFacilities>(RealSecurityFacilities.class);
        util.exportExcel(response, list, "实有安防设施数据");
    }

    /**
     * 获取实有安防设施详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(realSecurityFacilitiesService.selectRealSecurityFacilitiesById(id));
    }

    /**
     * 新增实有安防设施
     */
    @Log(title = "实有安防设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RealSecurityFacilities realSecurityFacilities)
    {
        return toAjax(realSecurityFacilitiesService.insertRealSecurityFacilities(realSecurityFacilities));
    }

    /**
     * 修改实有安防设施
     */
    @Log(title = "实有安防设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RealSecurityFacilities realSecurityFacilities)
    {
        return toAjax(realSecurityFacilitiesService.updateRealSecurityFacilities(realSecurityFacilities));
    }

    /**
     * 删除实有安防设施
     */
    @Log(title = "实有安防设施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(realSecurityFacilitiesService.deleteRealSecurityFacilitiesByIds(ids));
    }

    /**
     * 功能：设备类型下拉框查询
     * @return
     */
    @GetMapping("/getSecurityFacilitiesType")
    public R getSecurityFacilitiesType()
    {
        List<RealSecurityFacilitiesType> list = realSecurityFacilitiesService.getSecurityFacilitiesType();
        return R.ok(list);
    }

    /**
     * 根据id查询设备信息
     * @return
     */
    @GetMapping("/getSecurityFacilitiesInfoById/{id}")
    public R<RealSecurityFacilities> getSecurityFacilitiesInfoById(@PathVariable("id") Long id)
    {
        RealSecurityFacilities realSecurityFacilities = realSecurityFacilitiesService.getSecurityFacilitiesInfoById(id);
        return R.ok(realSecurityFacilities);
    }

    /**根据小区id获取设备列表*/
    @GetMapping("/getGateByDictId/{id}")
        public R<List<RealSecurityFacilities>> getGateByDictId(@PathVariable("id") Long id)
    {
        List<RealSecurityFacilities> list = realSecurityFacilitiesService.getGateByDictId(id);
        return R.ok(list);
    }

        /**
         * 功能：查询设备下拉框
         */
        @GetMapping("/getSecurityFacilitiesCount")
        public R getSecurityFacilitiesCount()
        {
            List<RealSecurityFacilities> list = realSecurityFacilitiesService.getSecurityFacilitiesCount();
            return R.ok(list);
        }

}
